package main

import (
	"errors"
	"fmt"
)

func main() {
	tryRecover()
}

func tryRecover() {
	defer func() { // 匿名函数
		r := recover() // recover 是interface可以接受任何类型
		if err, ok := r.(error); ok {
			fmt.Println("Error occurred:", err)
		} else {
			panic(fmt.Sprintf(
				"I don't know what to do: %v", r))
		}
	}()
	// myError()
	dividedByZero()
}

func myError() {
	panic(errors.New("this is recover"))
	panic(123)
}

func dividedByZero() {
	b := 0
	a := 1 / b
	fmt.Println(a)
}
